using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Web;

namespace MeetingRoom.Data.Implementation
{
    /// <summary>
    /// Summary description for SimpleScheduleDao
    /// </summary>
    public abstract class SimpleScheduleDao
    {
        public SimpleScheduleDao()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        #region IScheduleDao Members

        public static void Create(MeetingRoom.Domain.Schedule schedule)
        {
            string insert = "insert into t_schedule (schedule_id, name, meetingroomtype_id, [begin], [end], applicant_id, status) values(@ScheduleId, @Name, @MeetingRoomTypeId, @BeginTime, @EndTime, @ApplicantId, @Status)";

            SqlCommand command = new SqlCommand(insert);

            SqlParameter scheduleIdParam = new SqlParameter("@ScheduleId", schedule.Id);
            command.Parameters.Add(scheduleIdParam);

            SqlParameter nameParam = new SqlParameter("@Name", schedule.Name);
            command.Parameters.Add(nameParam);

            SqlParameter meetingRoomTypeIdParam = new SqlParameter(
                "@MeetingRoomTypeId", schedule.MeetingRoomType.Id);
            command.Parameters.Add(meetingRoomTypeIdParam);

            SqlParameter beginParam = new SqlParameter(
                "@BeginTime", schedule.Duration.Begin);
            command.Parameters.Add(beginParam);

            SqlParameter endParam = new SqlParameter(
                "@EndTime", schedule.Duration.End);
            command.Parameters.Add(endParam);

            SqlParameter applicantIdParam = new SqlParameter(
                "@ApplicantId", schedule.Applicant.Id);
            command.Parameters.Add(applicantIdParam);

            SqlParameter statusParam = new SqlParameter(
                "@Status", schedule.Status);
            command.Parameters.Add(statusParam);

            using (SqlConnection conn = new SqlConnection(
                ConfigurationSettings.AppSettings["connectionString"]))
            {
                command.Connection = conn;
                command.Connection.Open();

                command.CommandText = insert;
                command.ExecuteNonQuery();
            }
        }

        public static void Update(MeetingRoom.Domain.Schedule schedule)
        {
            throw new Exception("The method or operation is not implemented.");
        }

        public static void Delete(MeetingRoom.Domain.Schedule schedule)
        {
            throw new Exception("The method or operation is not implemented.");
        }

        #endregion
    }
}